﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using nelech.Models.DBModel;

namespace nelech.Controllers.Utils
{
    public class NearPlaceComparer : IComparer<Place>
    {
        #region IComparer<Place> Members

        private float targetLon;
        private float targetLat;

        public NearPlaceComparer(float targetLon, float targetLat)
        {
            this.targetLon = targetLon;
            this.targetLat = targetLat;
        }

        public int Compare(Place x, Place y)
        {
            var distCompare = SharedUtils.Distance(y.lon, y.lat, targetLon, targetLat) -
                SharedUtils.Distance(x.lon, x.lat, targetLon, targetLat);
            if (distCompare < 0)
                return 1;
            if (distCompare > 0)
                return -1;
            return 0;
        }

        #endregion
    }

    public class NearTrackComparer : IComparer<Track>
    {
        #region IComparer<Track> Members

        private float targetLon;
        private float targetLat;

        public NearTrackComparer(float targetLon, float targetLat)
        {
            this.targetLon = targetLon;
            this.targetLat = targetLat;
        }

        public int Compare(Track x, Track y)
        {
            var distCompare = SharedUtils.Distance(y.lon, y.lat, targetLon, targetLat) -
                 SharedUtils.Distance(x.lon, x.lat, targetLon, targetLat);
            if (distCompare < 0)
                return 1;
            if (distCompare > 0)
                return -1;
            return 0;
        }

        #endregion
    }

    public class NearAttrComparer : IComparer<Attraction>
    {
        #region IComparer<Attraction> Members

        private float targetLon;
        private float targetLat;

        public NearAttrComparer(float targetLon, float targetLat)
        {
            this.targetLon = targetLon;
            this.targetLat = targetLat;
        }

        public int Compare(Attraction x, Attraction y)
        {
            var distCompare = SharedUtils.Distance(y.lon, y.lat, targetLon, targetLat) -
                 SharedUtils.Distance(x.lon, x.lat, targetLon, targetLat);
            if (distCompare < 0)
                return 1;
            if (distCompare > 0)
                return -1;
            return 0;
        }

        #endregion
    }


    public class NearMaayanComparer : IComparer<Maayan>
    {
        #region IComparer<Maayan> Members

        private float targetLon;
        private float targetLat;

        public NearMaayanComparer(float targetLon, float targetLat)
        {
            this.targetLon = targetLon;
            this.targetLat = targetLat;
        }

        public int Compare(Maayan x, Maayan y)
        {
            var distCompare = SharedUtils.Distance(y.lon, y.lat, targetLon, targetLat) -
                SharedUtils.Distance(x.lon, x.lat, targetLon, targetLat);
            if (distCompare < 0)
                return 1;
            if (distCompare > 0)
                return -1;
            return 0;

        #endregion
        }
    }

    public class NearZimerComparer : IComparer<Zimer>
    {
        #region IComparer<Zimer> Members

        private float targetLon;
        private float targetLat;

        public NearZimerComparer(float targetLon, float targetLat)
        {
            this.targetLon = targetLon;
            this.targetLat = targetLat;
        }

       

        public int Compare(Zimer x, Zimer y)
        {
            var distCompare = SharedUtils.Distance(y.lon, y.lat, targetLon, targetLat) -
                 SharedUtils.Distance(x.lon, x.lat, targetLon, targetLat);
            if (distCompare < 0)
                return 1;
            if (distCompare > 0)
                return -1;
            return 0;
        }

        #endregion
    }
}
